home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPPLIB.ZIP / TCOMMAND.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  3KB  |  121 lines

  1. // tcommand.cpp -- Test command class
  2.  
  3. //#include <stream.hpp>
  4. #include <iostream.h>
  5. #include <conio.h>
  6. #include "key.h"
  7. #include "selector.h"
  8. #include "command.h"
  9.  
  10. /* -- Test-function prototypes */
  11.  
  12. void pause(void);
  13. void runtest(void);
  14.  
  15. /* -- Derived command classes */
  16.  
  17. class openCommand : public command {
  18.   public:
  19.     openCommand() : command("Open") { }
  20.     virtual void performCommand(void);
  21. };
  22.  
  23. class closeCommand : public command {
  24.   public:
  25.     closeCommand() : command("Close") { }
  26.     virtual void performCommand(void);
  27. };
  28.  
  29. class saveCommands : public command {
  30.   public:
  31.     saveCommands(const char *s, int cn) : command(s) 
  32.         { cmdNum = cn; }
  33.     virtual void performCommand(void);
  34. };
  35.  
  36. class quitCommand : public command {
  37.   public:
  38.     quitCommand() : command("Quit <Esc>") { }
  39.     virtual void performCommand(void);
  40. };
  41.  
  42. main()
  43. {
  44.   cwindow::startup();
  45.   runtest();
  46.   cwindow::shutDown();
  47.   exit(0);
  48. }
  49.  
  50. /* -- Wait for a <Spacebar> */
  51.  
  52. void pause(void)
  53. {
  54.   cout << " Press <Spacebar>...";
  55.   while (getch() != ' ') ;
  56. }
  57.  
  58. /* -- Perform tests */
  59.  
  60. void runtest(void)
  61. {
  62.   winStruct ws = {
  63.     4, 20, 18, 7,  // row, column, width, height
  64.     0x07,          // text attribute
  65.     0x1e,          // border attribute
  66.     0x70,          // highlight attribute
  67.     1              // type, save text (yes)
  68.   };
  69.   selector *sel = new selector(ws, " Items ");
  70.   command *cp;
  71.  
  72.   sel->insertItem(new openCommand());
  73.   sel->insertItem(new closeCommand());
  74.   sel->insertItem(new saveCommands("Save", 1));
  75.   sel->insertItem(new saveCommands("Save-as", 2));
  76.   sel->insertItem(new quitCommand());
  77.  
  78.   while ((cp = (command *)(sel->getSelection())) != NULL) {
  79.     cp->performCommand();
  80.   }
  81.  
  82.   delete sel;
  83. }
  84.  
  85. /* -- The derived command-class implementations */
  86.  
  87. void openCommand::performCommand(void)
  88. {
  89.   cout << "\nOpen command.";
  90.   pause();
  91. }
  92.  
  93. void closeCommand::performCommand(void)
  94. {
  95.   cout << "\nClose command.";
  96.   pause();
  97. }
  98.  
  99. void saveCommands::performCommand(void)
  100. {
  101.   if (cmdNum == 1) 
  102.     cout << "\nSave command.";
  103.   else if (cmdNum == 2)
  104.     cout << "\nSave-as command.";
  105.  
  106.   pause();
  107. }
  108.  
  109. void quitCommand::performCommand(void)
  110. {
  111.   ungetKey(27);     // "Press" the <Esc> key
  112. }
  113.  
  114.  
  115. // Copyright (c) 1990 by Tom Swan. All rights reserved
  116. // Revision 1.00    Date: 11/01/1990   Time: 07:47 am
  117.  
  118. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  119. // Converted for Borland C++ 2.0
  120.  
  121.